package com.cat.dataStructure02;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-deletions-to-make-array-divisible/
 * @create 2025/11/2 18:21
 * @since JDK17
 */

public class Solution98 {
    int gcd(int x, int y) {
        return y == 0 ? x : gcd(y, x % y);
    }

    public int minOperations(int[] nums, int[] numsDivide) {
        Arrays.sort(nums);
        int n = nums.length, m = numsDivide.length, g = numsDivide[0];
        for (int i = 1; i < m; i++) {
            g = gcd(g, numsDivide[i]);
        }
        for (int i = 0; i < n; i++) {
            if (g % nums[i] == 0) {
                return i;
            }
        }

        return -1;
    }
}
